<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>客户列表</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

    <script src="/js/axios.min.js"></script>
    <script src="/js/vue.js"></script>
    <script src="/js/qs.min.js"></script>
    <script src="/js/jquery.js"></script>

    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        h3 a{
            text-decoration: none;
            color: #000000;
        }
    </style>
</head>
<body>
<h3>
    <a href="">我的供应商</a>
</h3>
    <div id="app">

        <div rel="value">
            <span>选择地区：</span>
            <template>
                <el-select v-model="value.pro"  placeholder="请选择" @change="selectCity">
                    <el-option
                            v-for="(pro,index) in provinces"
                            :key="index"
                            :label="pro"
                            :value="pro">
                    </el-option>
                </el-select>

                <el-select v-model="value.city" style="margin-left: 20px;" placeholder="请选择市" @change="selectCounty">
                    <el-option
                            v-for="(city,index) in typeCitys"
                            :key="index"
                            :label="city"
                            :value="city">
                    </el-option>
                </el-select>

                <el-select v-model="value.county" style="margin-left: 20px;" placeholder="请选择市">
                    <el-option
                            v-for="(county,index) in typeCountys"
                            :key="index"
                            :label="county"
                            :value="county">
                    </el-option>
                </el-select>
            </template>
            <span>企业名称</span>
            <el-input v-model="name" placeholder="请输入内容" style="width: 180px"></el-input>
            <el-button type="primary" icon="el-icon-search" @click="loadSuppliers">搜索</el-button>
        </div>

        <template>
            <el-table style="width: 100%"
                      :data="suppliers"
                      ref="supplierTable">
                <el-table-column label="id" width="80">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.id }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="供应商名称" width="180">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px"><a href="../companyAndProduct.html">{{ scope.row.name }}</a></span>
                    </template>
                </el-table-column>
                <el-table-column label="地址" width="250">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.address }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="联系电话" width="180">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.telephone }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="邮箱" width="180">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px;">{{ scope.row.email }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="主营业务" width="80">
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.business }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                        <el-button size="mini"  type="danger" slot="reference"><a href="/page/product/productList.html">订购</a></el-button>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block" style="margin-top: 10px;">
                <el-pagination @size-change="handleSizeChange"
                               @current-change="handleCurrentChange"
                               :current-page="currentPage"
                               :page-sizes="page_size"
                               :page-size="4"
                               layout="total, sizes, prev, pager, next, jumper"
                               :total="count"
                               :background="back">
                </el-pagination>
            </div>
            <el-dialog title="站点操作" :visible.sync="dialogFormVisible" width="500px" @close="closeDialog()">
                <el-form :model="supplier">
                    <el-form-item label="备注">
                        <el-input v-model="supplier.name" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="putSupplier()">确 定</el-button>
                </div>
            </el-dialog>
        </template>
    </div>
</body>
<script>


    new Vue({
        el: "#app",
        data(){
            return{
                // 当前页数
                currentPage: 1,
                // 订单总数
                count : 0,
                // 每页的数据
                page_size : [6,3],
                // 当前每页的数据
                pageSize : 6,
                // 分页背景
                back: true,
                suppliers: [],
                supplier: {},
                dialogFormVisible: false,
                flag: 0,
                name:"",
                provinces:["湖北省","湖南省","广东省","河南省","河北省","陕西省","广西省"],//省
                city:{
                    "湖北省":["武汉市","襄阳市","宜昌市","荆州市","恩施市"],
                    "湖南省":["长沙市","株洲市","湘潭市","衡阳市","邵阳市"],
                    "广东省":["广东市","深圳市","珠海市","中山市","佛山市"],
                    "河南省":["郑州市","开封市","洛阳市","南阳市","许昌市"],
                    "陕西省":["西安市","铜川市","宝鸡市","咸阳市","汉中市"],
                    "广西省":["南宁市","柳州市","桂林市","北海市","梧州市"]
                },//市
                county:{
                    "武汉市":["洪山区","东湖区","青山区","江夏区","江汉区"],
                    "荆州市":["荆州区","沙市区"],
                    "长沙市":["长沙县","善华县","湘潭县","湘阴县"],
                    "襄阳市":["襄城区","樊城区","襄州区","保康县"],
                    "株洲市":["茶陵县","炎陵县","芦淞县"],
                    "广东市":["黄埔区","花都区","天河区"],
                    "郑州市":["中原区","二七区","上街区"],
                    "西安市":["莲湖区","雁塔区","未央区"],
                    "南宁市":["江南区","青秀区","兴宁区"]
                },//区
                typeCitys:[],//选择的省下的市
                typeCountys:[],//选择的市下的县
                value:{
                    pro:'',
                    city:'',
                    county:''
                },
                name:'',

            }
        },
        methods:{
            loadSuppliers(){
                axios.get("/supplier/like?current=" + this.currentPage + "&pageSize=" + this.pageSize + "&province="
                    + this.value.pro+"&city=" + this.value.city + "&county=" + this.value.county + "&name=" + this.name)
                    .then(res => {
                        this.suppliers = res.data.records;
                        this.count = res.data.total;
                    });
            },
            // 更新
            putSupplier() {
                console.log(this.supplier);
                if(this.flag == 0){
                }else {
                    axios.put("/supplier", this.supplier)
                        .then(res => {
                            if(res.data == "ok"){
                                this.loadSuppliers();
                            }
                        });
                }
                this.dialogFormVisible = false;
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.loadSuppliers();
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.loadSuppliers();
            },
            handleEdit(index, row) {
                this.supplier = row;
                this.flag = 1;
                this.dialogFormVisible = true;
            },
            // 删除客户
            // handleDelete(index, row) {
            //     if(this.suppliers.length == 1){
            //         this.currentPage = this.currentPage - 1;
            //     }
            //     axios.delete("/supplier/" + row.id)
            //         .then(res => {
            //             if(res.data == "ok"){
            //                 this.loadSuppliers();
            //             }
            //         });
            // },
            //清空修改客户模态框数据
            closeDialog() {
                this.flag = 0;
                this.supplier = {};
            },
            //二级菜单
            selectCity(){
                this.value.city='';
                for( const k in this.provinces){
                    if(this.value.pro===this.provinces[k]){
                        this.typeCitys=this.city[this.value.pro]
                    }
                }
            },
            //三级菜单
            selectCounty(){
                this.value.county='';
                for(const k in this.typeCitys){
                    if(this.value.city===this.typeCitys[k]){
                        this.typeCountys=this.county[this.value.city];
                    }
                }
            },

        },
        mounted(){
            this.loadSuppliers();
            this.selectCity();
            this.selectCounty();
        }
    });
</script>
</html>